#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
ll a[N], b[N];
ll gcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = gcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
void f(ll& a1, ll& b1, ll a2, ll b2) {
  if (a1 > a2) swap(a1, a2), swap(b1, b2);
  ll c = a2 - a1;
  ll x, y;
  ll d = gcd(b1, b2, x, y);
  x = (__int128_t)x * c / d % (b2 / d);
  a1 = ((__int128_t)x * b1 + a1) % (b1 / d * b2);
  b1 = b1 / d * b2;
  if (a1 < 0) a1 += b1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> b[i] >> a[i];
  rep(i, 2, n) { f(a[1], b[1], a[i], b[i]); }
  cout << a[1];
  return 0;
}